"""
@name: zuoyegame
@author: liangrui
@projectname: pythonProject
"""
import random
class Role():
    def __init__(self,name,sex,blood=100):
        self.name = name
        self.sex = sex
        self.blood = blood
    def attack(self,other):
        fight1 = 10
        fight2 = 5
        if self.blood<=0:
            print("角色无法继续战斗")
        else:
            # 0，1表示有无装备防弹衣
            if random.choices([0, 1]) == 0:
                print(f"{other.name}没有装备防弹衣")
                other.blood = other.blood - fight1
            else:
                print(f"{other.name}装备了防弹衣")
                other.blood = other.blood - fight2
            if other.blood <= 0:
                print(f"{other.name}已阵亡，不能再进行攻击")
                exit()

class Room():
    def __init__(self, name):
        self.name = name
        self.member_list = []
    def add_member(self,role):
        if len(self.member_list)<2:
            self.member_list.append(role)
            role.Room = self
            print(f"{role.name}成功加入{self.name}房间")
        else:
            print(f"{role.name}加入{self.name}房间等候")

print('''************
1.创建角色
2.创建房间
3.加入房间
4.开始战斗
5.退出
*************''')
roles={}
rooms={}
while True:
    num1 = input("请输入你的选项: ")
    if num1 == "1":
       name, sex = input("请输入姓名、性别（空格分割）:").split(" ")
       roles[name]=Role(name,sex)
    elif num1 == "2":
        name = input("请输入房间的名字:")
        rooms[name]=Room(name)
    elif num1 == "3":
        print(f"当前房间的角色有{roles.keys()},当前房间有{rooms.keys()}")
        role_name, room_name = input("请输入你要选择的角色和房间名(空格分割): ").split(" ")
        rooms[room_name].add_member(roles[role_name])
    elif num1 == "4":
        while True:
            enter = random.choice([0, 1])
            if enter == 0:
                rooms[room_name].member_list[0].attack(rooms[room_name].member_list[1])
            else:
                rooms[room_name].member_list[1].attack(rooms[room_name].member_list[0])
        else:
            print("输入错误！请输入1-5选择操作！")
    else:
        print("输入有误！请重新输入！")